package org.jeecg.modules.demo.hd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.jeecg.modules.demo.hd.entity.AppTeamCommissionDetail;
import org.jeecg.modules.demo.hd.mapper.AppTeamCommissionDetailMapper;
import org.jeecg.modules.demo.hd.service.IAppTeamCommissionDetailService;
import org.jeecg.modules.demo.hd.vo.TeamCommissionTotalVO;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.transaction.Transactional;
import java.util.List;

/**
 * @Description: app_team_commission_detail
 * @Author: jeecg-boot
 * @Date: 2025-05-08
 * @Version: V1.0
 */
@Service
public class AppTeamCommissionDetailServiceImpl extends ServiceImpl<AppTeamCommissionDetailMapper, AppTeamCommissionDetail> implements IAppTeamCommissionDetailService {

    @Override
    @Transactional
    public boolean insert(AppTeamCommissionDetail detail) {
        // 查询 当天是否已经存在数据
        LambdaQueryWrapper<AppTeamCommissionDetail> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.apply("DATE_FORMAT(commission_day,'%Y-%m-%d') = DATE_FORMAT({0},'%Y-%m-%d')", detail.getCommissionDay())
                .eq(AppTeamCommissionDetail::getUserId, detail.getUserId())
                .eq(AppTeamCommissionDetail::getParentUser, detail.getParentUser());
        if (this.baseMapper.selectCount(queryWrapper) > 0) {
            return false;
        }
        this.baseMapper.insert(detail);
        return true;
    }

    @Override
    public List<TeamCommissionTotalVO> queryCommissionTotalByDay(String day) {
        LambdaQueryWrapper<AppTeamCommissionDetail> queryWrapper = Wrappers.lambdaQuery();
//        queryWrapper.apply("",AppTeamCommissionDetail::getCommissionDay, detail.getCommissionDay());
        queryWrapper.apply("DATE_FORMAT(commission_day,'%Y-%m-%d') = DATE_FORMAT({0},'%Y-%m-%d')", day);
        List<AppTeamCommissionDetail> appTeamCommissionDetails = this.baseMapper.selectList(queryWrapper);
        return null;
    }
}
